/**
 * 控制台输出工具
 * 用于美化环境配置信息的控制台输出
 */

/**
 * 输出环境配置信息
 * @param {Object} envConfig - 环境配置对象
 */
export function logEnvironmentConfig(envConfig) {



  console.log(
    "%c🚀 项目启动成功！",
    "color: #4CAF50; font-size: 18px; font-weight: bold;"
  );

  // 使用 console.group 创建可折叠的组
  // console.groupCollapsed(
  //   "%c📋 环境配置信息 (点击展开)",
  //   "color: #2196F3; font-size: 16px; font-weight: bold; cursor: pointer;"
  // );
  console.log(
    "%c🔧 钉钉环境:",
    "color: #FF9800; font-weight: bold;",
    envConfig.DINGTALK? "✅ 已启用" : "❌ 未启用"
  );
  
  
  console.log(
    "%c🌐 API地址:",
    "color: #9C27B0; font-weight: bold;",
    envConfig.URL
  );
  console.log(
    "%c🏷️  重定向:",
    "color: #607D8B; font-weight: bold;",
    envConfig.REDIRECT
  );
  console.log(
    "%c🏷️  环境类型:",
    "color: #607D8B; font-weight: bold;",
    envConfig.ENVIRONMENT
  );
  console.log(
    "%c📡 网络状态:",
    "color: #00BCD4; font-weight: bold;",
    envConfig.ISNETWORKING ? "✅ 在线" : "❌ 离线"
  );
  console.log(
    "%c📦 项目名称:",
    "color: #795548; font-weight: bold;",
    envConfig.NAME
  );
  console.log(
    "%c📌 版本号:",
    "color: #E91E63; font-weight: bold;",
    envConfig.VERSION
  );
  console.log(
    "%c⚡ 全局加载 loading:",
    "color: #FF5722; font-weight: bold;",
    envConfig.GLOBAL_LOADING ? "✅ 已启用" : "❌ 已禁用"
  );

  // // 结束组
  // console.groupEnd();

  console.log(
    "%c🎉 应用已准备就绪！",
    "color: #4CAF50; font-size: 14px; font-weight: bold;"
  );
}

/**
 * 输出项目启动信息
 */
export function logProjectStart() {
  const envConfig = {
    DINGTALK: __DINGTALK__,
    URL: __URL__,
    ENVIRONMENT: __ENVIRONMENT__,
    ISNETWORKING: __ISNETWORKING__,
    NAME: __NAME__,
    VERSION: __VERSION__,
    GLOBAL_LOADING: __GLOBAL_LOADING__,
    REDIRECT: __REDIRECT__,
  };

  logEnvironmentConfig(envConfig);
}

/**
 * 输出自定义信息
 * @param {string} message - 要输出的信息
 * @param {string} type - 信息类型 (success, info, warning, error)
 */
export function logMessage(message, type = "info") {
  const styles = {
    success: "color: #4CAF50; font-weight: bold;",
    info: "color: #2196F3; font-weight: bold;",
    warning: "color: #FF9800; font-weight: bold;",
    error: "color: #F44336; font-weight: bold;",
  };

  const icons = {
    success: "✅",
    info: "ℹ️",
    warning: "⚠️",
    error: "❌",
  };

  console.log(`%c${icons[type]} ${message}`, styles[type]);
}

/**
 * 输出可折叠的详细信息
 * @param {string} title - 标题
 * @param {Object} data - 要显示的数据
 * @param {boolean} collapsed - 是否默认折叠
 */
export function logCollapsibleInfo(title, data, collapsed = true) {
  const method = collapsed ? console.groupCollapsed : console.group;

  method(`%c${title}`, "color: #2196F3; font-weight: bold; cursor: pointer;");

  if (typeof data === "object") {
    console.table(data);
  } else {
    console.log(data);
  }

  console.groupEnd();
}

/**
 * 输出性能信息
 * @param {string} label - 性能标签
 * @param {Function} fn - 要测试的函数
 */
export function logPerformance(label, fn) {
  console.groupCollapsed(
    `%c⏱️ 性能测试: ${label}`,
    "color: #FF9800; font-weight: bold; cursor: pointer;"
  );

  const start = performance.now();
  const result = fn();
  const end = performance.now();

  console.log(`执行时间: ${(end - start).toFixed(2)}ms`);
  console.log(`结果:`, result);

  console.groupEnd();

  return result;
}
